progresstracker: Don't hand out NaN
authorBenjamin Otte <otte@redhat.com>
Sun, 12 Nov 2017 05:19:00 +0000 (06:19 +0100)
committerBenjamin Otte <otte@redhat.com>
Sun, 12 Nov 2017 05:22:34 +0000 (06:22 +0100)
When the duration is set to 0, clamp it to 1us. This way we're almost
correct: We should really instantly finish, but we don't. But we do
respect the delay.

Doing this properly would require some refactoring of how the progress
tracker actually maintains progress, and this is just a quick fix.

gtk/gtkprogresstracker.c

index 81cca35d19541ab1c299f99059578323030973ab..0ddcbfbe4c9a0e0881288762c5507c1041cb5ba3 100644 (file)
@@ -82,7 +82,7 @@ gtk_progress_tracker_start (GtkProgressTracker *tracker,
   tracker->is_running = TRUE;
   tracker->last_frame_time = 0;
   tracker->duration = duration;
-  tracker->iteration = - delay / (gdouble) duration;
+  tracker->iteration = - delay / (gdouble) MAX (duration, 1);
   tracker->iteration_count = iteration_count;
 }
 
@@ -108,7 +108,7 @@ gtk_progress_tracker_finish (GtkProgressTracker *tracker)
  **/
 void
 gtk_progress_tracker_advance_frame (GtkProgressTracker *tracker,
-                                 guint64 frame_time)
+                                    guint64             frame_time)
 {
   gdouble delta;
 
@@ -127,7 +127,7 @@ gtk_progress_tracker_advance_frame (GtkProgressTracker *tracker,
       return;
     }
 
-  delta = (frame_time - tracker->last_frame_time) / gtk_slowdown / tracker->duration;
+  delta = (frame_time - tracker->last_frame_time) / gtk_slowdown / MAX (tracker->duration, 1);
   tracker->last_frame_time = frame_time;
   tracker->iteration += delta;
 }